/*
 * 
 *  This file is part of Sourceprojects.org Lycia Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.lycia.test;

import static org.junit.Assert.assertEquals;

import java.io.InputStream;

import org.junit.Test;
import org.sourceprojects.lycia.LyciaConfigurator;
import org.sourceprojects.lycia.LyciaParser;
import org.sourceprojects.lycia.LyciaParserFactory;
import org.sourceprojects.lycia.exceptions.LyciaParsingException;
import org.sourceprojects.lycia.test.impl.ComplexXPathTagParser;

public class XpathComplexTestCase {

	@Test
	public void testComplexeXPathParsing() throws LyciaParsingException {
		final InputStream is = getClass().getClassLoader().getResourceAsStream(
				"xpathcomplex.xml");
		final LyciaParser<StringBuilder> parser = LyciaParserFactory
				.newInstance();
		final LyciaConfigurator<StringBuilder> configurator = parser
				.getConfigurator();

		parser.setValidatingSchema(false);
		parser.getParserContext().setContextObject(new StringBuilder());
		configurator.addTagDefinitionParser(new ComplexXPathTagParser());

		parser.parse(is);

		final StringBuilder sb = parser.getParserContext().getContextObject();
		assertEquals("Addition: number1 - 10\n" + "Addition: number2 - 20\n"
				+ "Substract: number1 - 20\n" + "Substract: number2 - 10\n"
				+ "Multiply: number1 - 10\n" + "Multiply: number2 - 20\n"
				+ "Divide: number1 - 20\n" + "Divide: number2 - 10\n", sb
				.toString());
	}
}
